﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Common;
using MongoDB.Models;
using System.Data;
using System.Configuration;

namespace MongoDB
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入转换的表名：");
            String[] tbs = Console.ReadLine().Split(',');
            String SqlConn = ConfigurationManager.AppSettings["SqlConnection"];
            MongoDBbase MongodbBase = new MongoDBbase();
            foreach (String tb in tbs)
            {
                for (int i = 0; i < 1000; i++)
                {
                    using (DataSet ds = SqlHelper.ExecuteDataset(SqlConn, "sp_GetLimit", tb, i * 100000+1, (i+1) * 100000))
                    {
                        if (ds.Tables[0].Rows.Count < 100000) i = 1000;
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            switch (tb)
                            {
                                case "Tianya_User":
                                    MongodbBase.Insert<Tianya>(new Tianya()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Email = row.Field<String>("Email"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                case "Duduniu_User":
                                    MongodbBase.Insert<Duduniu>(new Duduniu()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Email = row.Field<String>("Email"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                case "_7k7k_User":
                                    MongodbBase.Insert<_7k7k>(new _7k7k()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                case "Renren_User":
                                    MongodbBase.Insert<Renren>(new Renren()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                case "Weibo_User":
                                    MongodbBase.Insert<Weibo>(new Weibo()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                case "Zhenai_User":
                                    MongodbBase.Insert<Zhenai>(new Zhenai()
                                    {
                                        _id = row.Field<Int32>("ID"),
                                        UserName = row.Field<String>("UserName"),
                                        Password = row.Field<String>("Password")
                                    });
                                    break;
                                default:break;
                            }
                        }
                    }
                }
            }
        }

    }
}
